﻿Imports System.Data.SqlClient

Public Class adm_findcolumn
    Inherits System.Web.UI.Page


    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim strHtml As String = ""
        Dim strCID, strName As String
        Dim HTMLString As String = ""
        Dim sSQL As String = ""
        Dim objfind As New GetData
        Dim objrd As SqlDataReader = Nothing
        Dim ps As New PreparedStatement(sSQL)
        Dim strErr As String = ""
        If (Session("admin_ID") <> Nothing And Session("admin_ID") <> "") Then
            If Trim(Request("did")) = "del" Then
                Dim strErr1 As String = ""
                Dim strErr2 As String = ""
                strCID = Trim(Request("aid"))
                sSQL = "delete from Columns where Column_ID=@delId"
                ps.addParameter("delId", strCID)
                ps.strSql = sSQL
                objfind.es(ps, strErr1)
                sSQL = "update Column_New set Column_ID='' where Column_ID=@delId"
                ps.strSql = sSQL
                objfind.es(ps, strErr2)
                If strErr1 = "" And strErr2 = "" Then
                    result.InnerHtml = ""
                    result.InnerHtml = "<center><b><font color=""#FF0000""> Delete Column Success！</font></b></center>"
                Else
                    result.InnerHtml = ""
                    result.InnerHtml = "<center><b><font color=""#FF0000"">Error！</font></b><p>" & strErr1 & strErr2 & "</p></center>"
                End If
            End If

            sSQL = "select * from Columns where lang_flag='en'"
            ps.strSql = sSQL
            Dim conn As SqlConnection = objfind.getConn()

            objrd = objfind.dr(ps, strErr, conn, objrd)
            If objrd.HasRows Then
                strHtml += "<table class='minorbox' cellspacing='1' width='100%' border=""0""  style=""background-color:#3399FF"">"
                strHtml += "<tr	><td class='gridheader'  style=""background-color:#AACCFF"">Column ID</td>"
                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Column Name</td>"
                strHtml += "<td class='gridheader' style=""background-color:#AACCFF"">Operation</td>"
                While (objrd.Read())
                    strCID = objrd("Column_ID").ToString
                    strName = objrd("Column_Name").ToString
                    HTMLString = HTMLString & vbCr & vbTab & vbTab & "<tr>"
                    HTMLString = HTMLString & "<td valign=""top""  style=""background-color:#FFF"">" & strCID & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF"">" & strName & "&nbsp;</td>"
                    HTMLString = HTMLString & "<td valign=""top"" style=""background-color:#FFF""><a href=""adm_columnnews.aspx?aid=" & strCID & "&langflag=en"">News</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=""adm_editcolumn.aspx?aid=" & strCID & """>Edit</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href=""adm_findcolumn.aspx?aid=" & strCID & "&did=del"">Delete</a></td>"
                End While
                HTMLString = HTMLString & "</table>"
                strHtml += HTMLString
            Else
                strHtml = "No Column was found"
            End If
            objfind.closeConn(conn)

            searchResult.InnerHtml = strHtml
        Else
            Response.Redirect("../adm_login.aspx")
        End If
    End Sub
End Class